//
//  UserDataSingleton.m
//  CommunityNannyO2O
//
//  Created by apple on 15/7/20.
//  Copyright (c) 2015年 Apple. All rights reserved.
//

#import "UserDataSingleton.h"
#import "SIAlertView.h"
#import "LoginViewController.h"
#import "AccountTool.h"
#import "UIImageView+WebCache.h"

static UserDataSingleton * instance = nil;

@implementation UserDataSingleton

+(UserDataSingleton*)shareInstance
{
    if(instance == nil)
    {
        instance = [[super allocWithZone:nil]init];
    }
    return instance;
}

+(id)allocWithZone:(NSZone *)zone
{
    return [UserDataSingleton shareInstance];
}

-(void)LoginWithUserId:(NSString *)userId
                 MidiId:(NSString *)midiId
               NickName:(NSString *)nickName
               RealName:(NSString *)realName
                  Email:(NSString *)email
                  Phone:(NSString *)phone
               National:(NSString *)national
                    Sex:(NSString *)sex
                People:(NSString *)people
                IdCard:(NSString *)idCard
              Birthday:(NSString *)birthday
               HeadImg:(NSString *)headImg
{
    self.user_id = userId;
    self.midi_id = midiId;
    self.nickname = nickName;
    self.real_name = realName;
    self.eamil = email;
    self.phone = phone;
    self.nationality = national;
    self.sex = sex;
    self.people = people;
    self.id_card = idCard;
    self.birthday = birthday;
    self.head_img = headImg;
    
    [AccountTool LoginWithUserId:userId
                          MidiId:midiId
                        NickName:nickName
                        RealName:realName
                           Email:email
                           Phone:phone
                        National:national
                             Sex:sex
                          People:people
                          IdCard:idCard
                        Birthday:birthday
                         HeadImg:headImg];
}

-(void)getUserInfo
{
    self.user_id = [AccountTool takeUserId];
    self.clientId = [AccountTool takeClientId];
    self.midi_id = [AccountTool takeMidiId];
    self.nickname = [AccountTool takeNickName];
    self.real_name = [AccountTool takeRealName];
    self.eamil = [AccountTool takeEmail];
    self.phone = [AccountTool takePhone];
    self.nationality = [AccountTool takeNational];
    self.sex = [AccountTool takeSex];
    self.people = [AccountTool takePeople];
    self.id_card = [AccountTool takeIdCard];
    self.birthday = [AccountTool takeBirthday];
    self.head_img = [AccountTool takeHeadImg];
}

-(void)setGeTuiClientID:(NSString *)clientId
{
    self.clientId = clientId;
    
    [AccountTool setGeTuiClientId:clientId];
}

-(NSString *)getGeTuiClientID
{
    return [AccountTool takeClientId];
}

-(BOOL)isLogin
{
    return [AccountTool checkLogin];
}

-(void)loginOut
{
    self.user_id = @"";
    self.midi_id = @"";
    self.nickname = @"";
    self.real_name = @"";
    self.eamil = @"";
    self.phone = @"";
    self.nationality = @"";
    self.sex = @"";
    self.people = @"";
    self.id_card = @"";
    self.birthday = @"";
    self.head_img = @"";
    
    [self.majorList removeAllObjects];
    self.majorList = nil;
    
    self.isGotSelfInfo = NO;
    self.isSelfInfoChange = NO;
    self.isOrderChange = NO;
    
    [AccountTool loginOut];
}

-(void)pleaseLogin:(UIViewController *)vc
{
    LoginViewController *login = [LoginViewController create];
    login.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    login.modalPresentationStyle = UIModalPresentationOverCurrentContext;
    login.definesPresentationContext = YES;
    
    [vc.navigationController presentViewController:[[UINavigationController alloc]initWithRootViewController:login] animated:YES completion:^{
    }];
}

-(void)setLocalHeadImageData:(UIImage *)image
{
    if (self.headImageView == nil)
    {
        self.headImageView = [[UIImageView alloc] init];
    }
    
    [self.headImageView setImage:image];
}

-(UIImage *)getLocalHeadImage
{
    if (self.headImageView)
    {
        return self.headImageView.image;
    }
    
    return nil;
}

-(void)clearLocalHeadImage
{
    self.headImageView = nil;
}

@end
























